/*
 * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
 */
/*jslint anon:true, sloppy:true, nomen:true*/
YUI.add('Stores', function(Y, NAME) {

	/**
	 * The Stores module.
	 * 
	 * @module Stores
	 */

	/**
	 * Constructor for the Controller class.
	 * 
	 * @class Controller
	 * @constructor
	 */
	Y.namespace('mojito.controllers')[NAME] = {

		init : function(config) {
			this.config = config;
		},

		/**
		 * Method corresponding to the 'index' action.
		 * 
		 * @param ac
		 *            {Object} The ActionContext that provides access to the
		 *            Mojito API.
		 */
		index : function(ac) {
			var filters = {
				conditions : [ {
					key : 'name',
					unary :'true',
					op : 'IS NOT NULL'
				} ],
				order : [ {
					key : 'id',
					op : 'DESC'
				}]
			};
			var limit = ac.params.getFromMerged('limit');
			var offset = ac.params.getFromMerged('offset');

			ac.models.StaticModelStore.getAllStores(function(err, data) {
				if (err) {
					ac.error(err);
					return;
				}
				ac.done({
					data : data
				});
			}, limit, offset, filters);
		}

	};

}, '0.0.1', {
	requires : [ 'mojito', 'StaticModelStore' ]
});
